/*任务管理*/

$(function load() {
    search();
})
function search() {
    var candidateUser = $("#userName").val();
    var s = {"candidateUser": candidateUser};
    $.ajax({
        type: "POST",
        url: "/flowTask/queryTask",
        dataType: "json",
        contentType:"application/json",
        data: JSON.stringify(s),
        success: function (data) {
            if (data.msg == 'success') {
                $("#content").empty();
                var html ="";
                if(data.list == null){
                    html +='<tr><td colspan="7">暂无任务</td></tr>';
                }
                $.each(data.list, function (k,v) {
                    var unixTimestamp = new Date( v.createTime) ;
                    var time =unixTimestamp.toLocaleString();
                    html +=
                        '<tr>'+
                        '<td>'+v.name+'</td>'+
                        '<td>'+time+'</td>'+
                        '<td>'+v.variables.applyUserId+'</td>'+
                        '<td>'+time+'</td>'+
                        '<td>'+v.variables.day+'</td>'+
                        '<td>'+v.variables.reason+'</td>'+
                        '<td>' +
                        '<button type="button" onclick="pass('+v.id+',1)">通过</button>' +
                        '<button type="button" onclick="pass('+v.id+',0)">不通过</button>' +
                        '<button type="button" onclick="show('+v.processInstanceId+')">查看流程图</button>'+
                        '</td></tr>';
                });
                $("#content").append(html);
            } else {
                 alert(data.msg)
            }
        }

    })
}

$(function record() {

})

function pass(taskId,status) {
       var msg =(status == 1 ? "同意": "不同意");
       var s ={"taskId":taskId, "isReviewPass":status,"message":msg}
        $.ajax({
            type: "POST",
            url: "/flowTask/completeTask",
            dataType: "json",
            contentType:"application/json",
            data: JSON.stringify(s),
            success:function (data) {
                if (data.msg == 'success') {
                    alert("审核成功");
                    window.location.reload();
                } else {
                    alert(data.msg)
                }
            }
        })
}

function show(id){
    var url = "/processDefinition/viewProcessInstanceImage?processInstanceId="+id;
    window.open(url,"_blank")

}

Date.prototype.toLocaleString = function() {
    return this.getFullYear() + "/" + (this.getMonth() + 1) + "/" + this.getDate() + "/ " + this.getHours() + ":" + this.getMinutes() + ":" + this.getSeconds();
};